<template>
    <div class="app-container calendar-list-container" v-loading="loading" element-loading-text="正在导出数据">
        <div style="position: fixed;z-index: 999;right: 20px;" class="flexEnd">

            <!-- <el-button
                class="el-button el-button--danger"
                style="font-size: 15px;"
                @click="cleartable()"
                v-if="tableInfo.length"
            >清空表格</el-button> -->

            <el-button
            type="button"
            class="el-button el-button--primary"
            @click="uploadForm"
            round
            size="medium"
            :loading="btnLoading"
            >
            {{saveToisEdict && this.$route.params.data.processName == this.listQuery1.processName?'保存':'确认提交'}}</el-button
            >
        </div>

      <div>
        <el-form :inline="true" label-width="112px" :model="listQuery1" ref="listQuery1" :rules="rules" label-position="right" style="width: 100%">
        <!-- <el-form-item label="工作中心:" prop="workCenter" required>
            <el-select
                v-model="listQuery1.workCenter"
                filterable
                @focus="getCenterList"
                class="re-item">
                <el-option
                    v-for="(item,index) in this.centerList"
                    :key="index"
                    :label="item"
                    :value="item">
                </el-option>
            </el-select>
        </el-form-item> -->
        <el-form-item label="工序大类:" prop="processType" required>
            <el-select
                v-model="listQuery1.processType"
                filterable
                @focus="getProcessType"
                class="re-item">
                <el-option
                    v-for="(item,index) in optionsProcessType"
                    :key="index"
                    :label="item.processType"
                    :value="item.processType">
                </el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="工序名称:" prop="processName" required>
             <el-cascader
                filterable
                :options="optionsProcessName"
                clearable
                v-model="listQuery1.processName"
                :show-all-levels="false"
                @change="isAliveProcess"></el-cascader>
            <!-- <el-input
                clearable
                v-model.trim="listQuery1.processName"
            ></el-input> -->
        </el-form-item>
        </el-form>

        <el-form label-width="112px" :inline="true" style="margin: 10px 0 10px 0">
            <el-form-item label="方案类型:" required>
                <el-select
                    v-model="programmeType"
                    filterable
                    class="re-item"
                    :disabled="saveToisEdict">
                    <el-option
                        v-for="(item,index) in this.programmeTypeList"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="process">
                <!-- <el-link type="primary">单价方案</el-link> -->
                <el-button
                    @click="addPriceScheme"
                    icon="el-icon-circle-plus-outline"
                    class="el-button el-button--primary"
                    style="font-size: 15px; position: fixed;z-index: 999;left:900px;"
                    round>
                </el-button>
            </el-form-item>
        </el-form>
      </div>

    <div style="margin: 20px 0 30px 112px;">

        <div v-for="(item,index) in priceSchemeList" :key="index"  style="display: flex;flex-direction: row;align-items: center;width: 560px;margin-right: 30px">
            <el-button
                icon="el-icon-delete"
                class="el-button el-button--danger"
                style="font-size: 15px;"
                @click="deletePriceScheme(item,index)"
            ></el-button>
            <el-form :model="item" ref="item" :rules="rules" style="margin: 10px 0 10px 20px">
                <el-form-item>
                        <!-- <el-select
                            v-model="item.paramName"
                            filterable
                            class="re-item"
                            style="width: 80px"
                            placeholder="参数名"
                            :disabled="item.isvalid">
                            <el-option
                                v-for="(item,index) in paramNameList"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select> -->

                    <el-cascader
                        filterable
                        :options="paramNameLists"
                        v-model="item.paramName"
                        placeholder="参数名"
                        style="width: 100px"
                        :disabled="item.isvalid"
                        @focus="getMaterial"
                        :show-all-levels="false">
                    </el-cascader>

                    <el-select
                        clearable
                        v-model="item.conditionleft"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in leftcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>

                    <el-input
                        class="input-new-tag"
                        @input="item.thicknessleft = item.thicknessleft.replace(/[^\d|\.]/g,'')"
                        v-model="item.thicknessleft"
                        size="small"
                        style="width: 70px"
                        :disabled="item.isvalid"
                    />

                    <el-select
                        clearable
                        v-model="item.conditionRight"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid"
                        v-if="item.conditionleft != '==' && item.conditionleft != '!='">
                        <el-option
                            v-for="(item,index) in rightcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>

                    <el-input
                        class="input-new-tag"
                         v-model="item.thicknessRight"
                        size="small"
                        style="width: 70px"
                        :disabled="item.isvalid"
                        v-if="item.conditionleft != '==' && item.conditionleft != '!='"
                    />
                    <template v-if="item.conditionleft && item.thicknessleft || item.conditionRight && item.thicknessRight">
                    <el-button
                        type="danger"
                        size="mini"
                        round
                        v-if="!item.isvalid"
                        @click="priceValid('price',item,index)"
                        style="margin-left: 10px">未校验</el-button>
                    <el-button
                        type="success"
                        size="mini"
                        round
                        v-else
                        style="margin-left: 10px"
                        @click="cancelValid(item,index)">已校验</el-button>
                    </template>

                </el-form-item>


                <el-form-item prop="process" label="关系" :disabled="item.disabled" label-width="80px" v-if="item.conditionleft && item.thicknessleft || item.conditionRight && item.thicknessRight">
                    <el-select
                        clearable
                        v-model="item.relation"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        @clear="item.paramName1='';item.conditionleft1='';item.thicknessleft1='';item.conditionRight1='';item.thicknessRight1=''"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in relationList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item v-if="item.relation">
                    <!-- <el-select
                            v-model="item.paramName1"
                            filterable
                            class="re-item"
                            style="width: 80px"
                            placeholder="参数名"
                            :disabled="item.isvalid">
                            <el-option
                                v-for="(item,index) in paramNameList.filter(items => items != item.paramName)"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                    </el-select> -->
                    <el-cascader
                        filterable
                        :options="paramNameLists.filter(items => items.value != item.paramName)"
                        v-model="item.paramName1"
                        placeholder="参数名"
                        style="width: 100px"
                        :disabled="item.isvalid"
                        :show-all-levels="false">
                    </el-cascader>
                    <el-select
                        clearable
                        v-model="item.conditionleft1"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in leftcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                    <el-input
                        class="input-new-tag"
                        v-model="item.thicknessleft1"
                        size="small"
                        style="width: 100px"
                        :disabled="item.isvalid"
                    />
                    <el-select
                        clearable
                        v-model="item.conditionRight1"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid"
                        >
                        <el-option
                            v-for="(item,index) in rightcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>

                    <el-input
                        class="input-new-tag"
                        v-model="item.thicknessRight1"
                        size="small"
                        style="width: 70px"
                        :disabled="item.isvalid"
                    />
                </el-form-item>

                <el-form-item prop="process" label="关系" :disabled="item.disabled" label-width="80px" v-if="item.conditionleft1 && item.thicknessleft1 || item.conditionRight1 && item.thicknessRight1">
                    <el-select
                        clearable
                        v-model="item.relation2"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        @clear="item.paramName2='';item.conditionleft2='';item.thicknessleft2='';item.conditionRight2='';item.thicknessRight2=''"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in relationList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item v-if="item.relation2">
                    <!-- <el-select
                            v-model="item.paramName1"
                            filterable
                            class="re-item"
                            style="width: 80px"
                            placeholder="参数名"
                            :disabled="item.isvalid">
                            <el-option
                                v-for="(item,index) in paramNameList.filter(items => items != item.paramName)"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                    </el-select> -->
                    <el-cascader
                        filterable
                        :options="paramNameLists.filter(items => items.value != item.paramName && items.value != item.paramName1)"
                        v-model="item.paramName2"
                        placeholder="参数名"
                        style="width: 100px"
                        :disabled="item.isvalid"
                        :show-all-levels="false">
                    </el-cascader>
                    <el-select
                        clearable
                        v-model="item.conditionleft2"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in leftcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                    <el-input
                        class="input-new-tag"
                        v-model="item.thicknessleft2"
                        size="small"
                        style="width: 70px"
                        :disabled="item.isvalid"
                    />
                    <el-select
                        clearable
                        v-model="item.conditionRight2"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid"
                        >
                        <el-option
                            v-for="(item,index) in rightcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>

                    <el-input
                        class="input-new-tag"
                        v-model="item.thicknessRight2"
                        size="small"
                        style="width: 100px"
                        :disabled="item.isvalid"
                    />
                </el-form-item>

                <el-form-item prop="process" label="关系" :disabled="item.disabled" label-width="80px" v-if="item.conditionleft2 && item.thicknessleft2 || item.conditionRight2 && item.thicknessRight2">
                    <el-select
                        clearable
                        v-model="item.relation3"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        @clear="item.paramName3='';item.conditionleft3='';item.thicknessleft3='';item.conditionRight3='';item.thicknessRight3=''"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in relationList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item v-if="item.relation3">
                    <!-- <el-select
                            v-model="item.paramName1"
                            filterable
                            class="re-item"
                            style="width: 80px"
                            placeholder="参数名"
                            :disabled="item.isvalid">
                            <el-option
                                v-for="(item,index) in paramNameList.filter(items => items != item.paramName)"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                    </el-select> -->
                    <el-cascader
                        filterable
                        :options="paramNameLists.filter(items => items.value != item.paramName && items.value != item.paramName1 && items.value != item.paramName2)"
                        v-model="item.paramName3"
                        placeholder="参数名"
                        style="width: 100px"
                        :disabled="item.isvalid"
                        :show-all-levels="false">
                    </el-cascader>
                    <el-select
                        clearable
                        v-model="item.conditionleft3"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid">
                        <el-option
                            v-for="(item,index) in leftcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>
                    <el-input
                        class="input-new-tag"
                        v-model="item.thicknessleft3"
                        size="small"
                        style="width: 70px"
                        :disabled="item.isvalid"
                    />
                    <el-select
                        clearable
                        v-model="item.conditionRight3"
                        filterable
                        class="re-item"
                        style="width: 70px"
                        placeholder="符号"
                        :disabled="item.isvalid"
                        >
                        <el-option
                            v-for="(item,index) in rightcompareList"
                            :key="index"
                            :label="item"
                            :value="item">
                        </el-option>
                    </el-select>

                    <el-input
                        class="input-new-tag"
                        v-model="item.thicknessRight3"
                        size="small"
                        style="width: 100px"
                        :disabled="item.isvalid"
                    />
                </el-form-item>


                <el-form-item prop="standard" required>
                    <el-select
                        v-model="item.standardType"
                        filterable
                        class="re-item"
                        style="width: 100px"
                        placeholder="标准值类型"
                        >
                        <el-option
                            v-for="(item,index) in standardTypeList"
                            :key="index"
                            :label="item.name"
                            :value="item.name">
                        </el-option>
                    </el-select>
                    <el-input
                        clearable
                        v-model.trim="item.standard"
                        style="width: 100px"
                    ></el-input>
                </el-form-item>
                 <el-divider></el-divider>

            </el-form>
        </div>
        <el-pagination
          @size-change="getMaterialOnlyForEdict"
          @current-change="getMaterialOnlyForEdict"
          :page-size.sync="limit"
          :current-page.sync="page"
          :page-sizes="[1,3,5,10,20,50,100, 200, 300, 400]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>

    </div>

    <el-dialog title="方案确认" :visible.sync="showProgramme" width="600px">

        <el-link type="primary" :underline="false">C：长；K：宽；H：厚；Z：重；GDSL：同一工单数量；CZ：材质；HJLJSL：焊接零件数量</el-link>

        <el-divider content-position="left" v-if="priceProgramme.length">{{programmeType+':'}}</el-divider>
        <div  v-for="(item,index1) in priceProgramme" :key="index1">
            <el-link type="primary" :underline="false">{{item.conditionIndex}}、</el-link>
            <el-link type="primary" :underline="false">{{item.eval}}</el-link>
        </div>
        <div class="errorBtn">
            <el-button type="warning" @click="showProgramme = false">取消</el-button>
            <el-button type="primary" :loading="submitLoading" @click="submit">确定</el-button>
        </div>
    </el-dialog>

  </div>
</template>


<script>
import { findProcessTypeGroup,saveMoneyConfig,verifyEquation,seldplate,findMoneyConfig,delMoneyConfig,groupProcessNo } from "@/api/processRoute"
import { getCenter } from '../../api/workSection.js'
export default {
    name: 'addprocessCategory',
    data () {
        return {
            loading: false,
            listQuery1: {},
            rules: {
                processType: [
                    { required: true, message: "工序大类不能为空", trigger: "change" },
                ],
                processName: [
                    { required: true, message: "工序名称不能为空", trigger: "change" },
                ],
            },
            optionsProcessType: [],
            btnLoading: false,
            leftcompareList: ['>','>=','==','!='],
            rightcompareList: ['<','<='],
            isValid: false,
            priceSchemeList: [],        //方案
            relationList: ['且'],
            centerList: '',
            paramNameList: ['长','宽','厚','重','同一工单数量','材质','焊接零件数量'],
            // ,{label:'加工次数',value:'JGCS'},{label:'周长',value:'ZC'},
            paramNameLists: [{label:'材质',value:'CZ',children: []},{label:'长',value:'C'},{label:'宽',value:'K'},{label:'厚',value:'H'},{label:'重',value:'Z'},{label:'同一工单数量',value:'GDSL'},{label:'焊接零件数量',value:'HJLJSL'},{label:'加工次数',value:'JGCS'},{label:'铆钉数量',value:'MDSL'},{label:'周长',value:'ZC'},{label:'装配零件数量',value:'ZP_LJSL'},{label:'装配普通螺钉数量',value:'ZP_LDSL'},{label:'装配外购件数量',value:'ZP_WGJSL'},{label:'装配打胶长度',value:'ZP_DJCD'},{label:'装配不锈钢螺钉数量',value:'ZP_BXGLDSL'},{label:'装配功率螺钉数量',value:'ZP_GLLDSL'},{label:'加工数量',value:'JGSL'},{label:'折弯刀数',value:'ZWDS'},{label:'单件重量',value:'DJZL'},{label:'单位平方',value:'DWPF'},{label:'连焊长度',value:'LHCD'},{label:'碰焊点数',value:'PHDS'},{label:'焊点数量',value:'HDSL'},
            {label:'加工周长',value:'JGZC'},{label:'人员定额',value:'RYDE'},{label:'喷涂面积',value:'PBMJ'},{label:'保护面积',value:'BHMJ'},{label:'保护个数',value:'BHGS'}],
            paramNameListsForEdict: [{label:'加工数量',value:'JGSL'},{label:'折弯刀数',value:'ZWDS'},{label:'单件重量',value:'DJZL'},{label:'单位平方',value:'DWPF'},{label:'连焊长度',value:'LHCD'},{label:'碰焊点数',value:'PHDS'},{label:'焊点数量',value:'HDSL'},{label:'加工周长',value:'JGZC'},{label:'装配零件数量',value:'ZP_LJSL'},{label:'装配普通螺钉数量',value:'ZP_LDSL'},{label:'装配外购件数量',value:'ZP_WGJSL'},{label:'装配打胶长度',value:'ZP_DJCD'},{label:'装配不锈钢螺钉数量',value:'ZP_BXGLDSL'},{label:'装配功率螺钉数量',value:'ZP_GLLDSL'},{label:'铆钉数量',value:'MDSL'},{label:'周长',value:'ZC'},{label:'加工次数',value:'JGCS'},{label:'焊接零件数量',value:'HJLJSL'},{label:'长',value:'C'},{label:'宽',value:'K'},{label:'厚',value:'H'},{label:'重',value:'Z'},
            {label:'同一工单数量',value:'GDSL'},{label:'材质',value:'CZ'},{label:'喷涂面积',value:'PBMJ'},{label:'保护面积',value:'BHMJ'},{label:'保护个数',value:'BHGS'}],
            priceProgramme: [],
            degreeProgramme: [],
            throwawayProgramme: [],
            quotaProgramme: [],
            showProgramme: false,
            ableparam: '',
            showvar: false,
            standardTypeList: [{name:'单价',value:'DJ'},{name:'单价1',value:'DJ1'},{name:'单价2',value:'DJ2'},{name:'单价3',value:'DJ3'},{name:'难度系数',value:'NDXS'},{name:'散单系数',value:'SDXS'},{name:'定额人数',value:'DERS'},{name:'加工数量',value:'JGSL'},{name:'加工次数',value:'JGCS'},{name:'铆钉数量',value:'MDSL'},{name:'折弯刀数',value:'ZWDS'},{name:'单件重量',value:'DJZL'},{name:'单位平方',value:'DWPF'},{name:'连焊长度',value:'LHCD'},{name:'碰焊点数',value:'PHDS'},{name:'焊点数量',value:'HDSL'},{name:'加工周长',value:'JGZC'}],
            createLoading: false,
            submitLoading: false,
            validArray: [],
            haveToDelete: [],
            countRequest: 0,
            countSuccess: 0,
            saveToisEdict: false,
            optionsProcessName: [],
            programmeTypeList: ['单价方案','单价1方案','单价2方案','单价3方案','难度系数方案','散单系数方案','定额人数方案'],
            programmeType: '',
            page:1,
            limit:10,
            total:0,
            // 修改过的arr
            upArr:[],
            // 旧arr
            oalArr: ''
        }
    },
    watch: {
      priceSchemeList: {
        handler(newVal,oldVal){
          // console.log('修改前',this.oalArr);
          // console.log('修改后',newVal);
          newVal.forEach((item, index) => {
            const odlItem = this.oalArr[index]
            if(JSON.stringify(item) !== JSON.stringify(odlItem)){
              if(this.oalArr){
                this.upArr.push(item)
                // if(this.upArr.length > 0){
                  // }
              }
            }
            // 去重
            this.upArr = this.upArr.reduce((acc, obj) => {
              if(obj.conditionIndex){
                const found = acc.find(item1 => item1.conditionIndex === obj.conditionIndex )
                if(!found) { acc.push(obj) }
              } else {
                acc.push(obj)
              }
              return acc
            }, [])
          })
          console.log('upArr',this.upArr);
          this.oalArr = JSON.parse(JSON.stringify(newVal))
        },
        deep: true,
      }
    },
    computed: {
      inputWid() {
        return function (value) {
            if(!value || (value.length <= 10)){
              return '150px'
            } else {
              return (150 + (String(value).length-10)*6) + 'px'
            }
        }
      }
    },
    mounted(){
      this.oalArr = this.priceSchemeList
    },
    methods: {
        // changeThicknessRight(value, targetIndex) {
        //   console.log('this.priceSchemeList', this.priceSchemeList);
        //   this.oalArr = JSON.parse(JSON.stringify(this.priceSchemeList));
        //   this.priceSchemeList.forEach((item, index) => {
        //     if(index === targetIndex) {
        //       item.thicknessRight = value;
        //     }
        //   });
        // },
        addPriceScheme(){
            if(!this.listQuery1.processName) return this.$message.error('工序名称不能为空！')
            if(!this.programmeType) return this.$message.error('方案类型不能为空！')
            // 新增的添加随机数id
            let randomNum = Math.floor(Math.random() * 100000000000).toString();
            let obj = {conditionIndex: randomNum,isvalid: false,paramName: '',conditionleft: '',thicknessleft: '',conditionRight: '',thicknessRight:'',paramName1: '',conditionleft1: '',thicknessleft1: '',conditionRight1: '',thicknessRight1:'',paramName2: '',conditionleft2: '',thicknessleft2: '',conditionRight2: '',thicknessRight2:'',paramName3: '',conditionleft3: '',thicknessleft3: '',conditionRight3: '',thicknessRight3:''}
            if(this.saveToisEdict){
                obj.isEdicted = true
                this.priceSchemeList.push(obj) //
                return
            }
            this.haveToAddOr(this.programmeType).then((res) => {
                if(res){
                    this.priceSchemeList = []
                    this.$message.error('该方案已存在，请前往修改')
                    return
                }
                this.priceSchemeList.push(obj)
            })
        },
        deletePriceScheme(item,index){
            if(this.saveToisEdict && item.timeId) { this.deleteData(item,index) }
            else { this.priceSchemeList.splice(index,1) }
            // this.priceSchemeList.splice(index,1)
            this.upArr = this.upArr.filter(item1 => {
              if(item1.conditionIndex !== item.conditionIndex){
                return item1
              }
            })
            console.log('upArr', this.upArr);
        },
        // 获取工作中心
        async getCenterList() {
          let {data} = await getCenter()
          this.centerList = data
          this.centerList.forEach((item,index) => {
            if(item.trim() == '焊喷车间'){ this.centerList.splice(index,1) }
          });
        },
        async getProcessType(){
            const data = await findProcessTypeGroup()
            if(data.code == '1'){
                this.optionsProcessType = data.data
            }
        },
        async saveMoneyConfig(obj){
            const data = await saveMoneyConfig(obj)
            if(data.code == '1'){
                this.countSuccess++
                if(this.$route.params.data && this.$route.params.data.processName){
                    if(this.countSuccess == this.haveToDelete.length){
                        this.$message.success(data.msg)
                        this.haveToDelete = []
                        this.showProgramme = false
                        this.countSuccess = 0
                        this.handleFilter(this.$route.params.data.processName,this.$route.params.data.processType,this.$route.params.data.schemeType)
                    } else if(this.$route.params.data.processName != this.listQuery1.processName && this.priceProgramme.length == this.countSuccess){
                        this.$message.success(data.msg)
                        this.showProgramme = false
                        this.countSuccess = 0
                        this.handleFilter(this.$route.params.data.processName,this.$route.params.data.processType,this.$route.params.data.schemeType)
                    }
                } else{
                    this.showProgramme = false
                    this.$message.success(data.msg)
                }
                // this.$router.go({
                //     path: '/pieceworkPlan',
                //     query: {
                //         close: true
                //     }
                // })
            }
        },
         uploadForm(){
            this.$refs['listQuery1'].validate(async (valid) => {
                if (valid) {
                  const list = []
                  const data = await findMoneyConfig({processName: this.$route.params.data.processName,schemeType: this.$route.params.data.schemeType,page: 1,limit: 9999,isDelete: 0})
                  console.log('data',data);
                  // this.$set(this.listQuery1, 'processName', this.$route.params.data.processName)
                  // this.$set(this.listQuery1, 'processType', this.$route.params.data.schemeType)
                  data.data.list.forEach((item,index) => {
                      if(item.isDelete != 1){
                      let obj = {}
                      obj.conditionIndex = item.conditionIndex
                      obj.standard = item.standard
                      obj.standardType = this.getValueStandardTypeName(item.standardType.trim())
                      obj.isvalid = true
                      obj.eval = item.conditionIf.trim()
                      obj.timeId = item.timeId
                      obj = Object.assign(obj,this.splitEval(item.conditionIf.trim()))
                      // this.programmeType = item.schemeType.trim()
                      list.push(obj)
                      }
                  })
                  console.log('list00',list);
                  // 修改原来的值
                  // const upList = []
                  list.forEach((item, index) => {
                    const findItem = this.upArr.find((item1, index1) =>{
                        return item.conditionIndex === item1.conditionIndex
                      })
                      if(findItem){
                        list[index] = findItem
                      }
                  })
                  console.log('list',list);
                  this.upArr.forEach(item => {
                    const bool = list.some(item1 =>{
                      return item.conditionIndex !== item1.conditionIndex
                    })
                    if(bool){
                      list.push(item)
                    } else {
                      console.log('不加');
                    }
                  })
                  // 添加的值
                  if(list.length === 0){
                    list.push(...this.upArr)
                  }
                  // if(this.upArr.length > 0){
                  //   this.upArr.forEach((item, index) => {
                  //     const findItem = list.find(item1 =>{
                  //       return item.conditionIndex !== item1.conditionIndex
                  //     })
                  //     console.log(index+1,findItem);
                  //     if(findItem){
                  //       console.log(index+1,findItem);
                  //       list.push(findItem)
                  //     }
                  //   })
                  // }
                  console.log(222,list);
                  // 去重
                  const SchemeList = list.reduce((acc, obj) => {
                    if(obj.conditionIndex){
                      const found = acc.find(item1 => item1.conditionIndex === obj.conditionIndex )
                      if(!found) { acc.push(obj)  }
                    } else {
                      acc.push(obj)
                    }
                    return acc
                  }, [])
                  // const SchemeList = list.filter((item,index, self) => self.indexOf(item.conditionIndex) === index)
                  // this.getMaterialOnlyForEdict()
                  console.log('SchemeList', SchemeList);
                  let priceSchemeList = SchemeList.filter(item => item.conditionleft && item.thicknessleft || item.conditionRight && item.thicknessRight)
                  let priceSchemeList1 = this.priceSchemeList.filter(item => item.conditionleft && item.thicknessleft || item.conditionRight && item.thicknessRight)
                  console.log('priceSchemeList',priceSchemeList)
                  if(priceSchemeList.length && priceSchemeList.some(item => !item.isvalid)) return this.$message.error(this.programmeType+'未校验完毕!')
                  if(priceSchemeList.length && priceSchemeList.some(item => !item.standard)) return this.$message.error(this.programmeType+'的定价未配置完毕!')
                  if(priceSchemeList.length){ this.priceProgramme = this.setSort(priceSchemeList) }
                  if(!priceSchemeList1.length) return this.$message.error('请先配置一个方案!')
                  this.showProgramme = true
                } else {

                }
            })
        },

        submit(){
            this.submitLoading = true
            setTimeout(() => {
                this.submitLoading = false
            }, 2000);
            if(this.$route.params.data && this.$route.params.data.processName != this.listQuery1.processName){
                this.lastUpform()
                return
            }
            this.haveToDelete = []
            if(this.$route.params.data && this.$route.params.data.processName){
                let haveTovalidArray = JSON.parse(JSON.stringify(this.priceProgramme))
                if(haveTovalidArray.some(item => item.isEdicted) || this.validArray.length != haveTovalidArray.length){
                    haveTovalidArray.forEach((item1,index1) => {
                        if(item1.timeId){ this.haveToDelete.push(item1.timeId) }
                    })
                } else {
                    this.validArray.forEach((item,index) => {
                        haveTovalidArray.forEach((item1,index1) => {
                            if(item.timeId == item1.timeId){
                                if(parseFloat(item.standard) != parseFloat(item1.standard) || item.standardType != item1.standardType){
                                    this.haveToDelete.push(item.timeId)
                                }
                            }
                        })
                    })
                }
            }
            if(this.haveToDelete.length){
                let set = new Set(this.haveToDelete)
                this.haveToDelete = Array.from(set)
            }
            console.log('需修改的',this.haveToDelete)
            // return console.log('需修改的',this.haveToDelete)
            if(this.haveToDelete.length) {
                this.countRequest = 0
                this.haveToDelete.forEach((item,index) => {
                    this.deleteRecordData(item)
                })
            } else if(this.saveToisEdict && !this.haveToDelete.length){
                this.haveToDelete = []
                this.showProgramme = false
                this.$message.success('保存成功!')
            } else {
                this.lastUpform()
            }
        },
        lastUpform(){
            let query = this.priceProgramme
            console.log(this.programmeType,query)
            query.forEach((item,index) => {
                let obj = Object.assign({},this.listQuery1)
                obj.schemeType = this.programmeType
                obj.conditionIf = item.eval
                obj.conditionIndex = item.conditionIndex
                if(item.standard){
                    obj.standard = item.standard
                    obj.standardType = this.getValueStandardType(item.standardType)
                }
                if(this.$route.params.data && this.$route.params.data.processName && this.haveToDelete.some(item1 => item1 == item.timeId)){
                    this.saveMoneyConfig(obj)
                } else if(this.$route.params.data && this.$route.params.data.processName && !item.timeId) {
                    this.saveMoneyConfig(obj)
                } else if(!this.$route.params.data) {
                    this.saveMoneyConfig(obj)
                } else if(this.$route.params.data && this.$route.params.data.processName && this.$route.params.data.processName!=this.listQuery1.processName) {
                    this.saveMoneyConfig(obj)
                }
            })
        },
        async deleteRecordData(timeId){
            const data = await delMoneyConfig({id: timeId})
            if(data.code == '500') return
            if(data.code == '2') return this.$message.error(data.msg)
            if(data.code == '1'){
                this.countRequest++
                if(this.countRequest == this.haveToDelete.length){
                    // this.haveToDelete = []
                    this.lastUpform()
                }
            }
        },
        getValueStandardType(key){
            let value = ''
            this.standardTypeList.forEach((item,index) => {
                if(item.name == key){
                    value = item.value
                }
            })
            return value
        },

        setSort(array){
            let finalArray = []
            if(array.length>1){
                let leftdata = array.filter(item => item.conditionleft && item.thicknessleft)
                let rightdata = array.filter(item => !item.conditionleft || !item.thicknessleft)

                for(var i = 0;i < leftdata.length-1;i++){
                    for(var j = 0;j < leftdata.length-i-1;j++){
                        if(parseFloat(leftdata[j].thicknessleft) > parseFloat(leftdata[j+1].thicknessleft)){
                            let temp = leftdata[j]
                            leftdata[j] = leftdata[j+1]
                            leftdata[j+1] = temp
                        }
                    }
                }
                for(var i = 0;i < rightdata.length-1;i++){
                    for(var j = 0;j < rightdata.length-i-1;j++){
                        if(parseFloat(rightdata[j].thicknessleft) > parseFloat(rightdata[j+1].thicknessleft)){
                            let temp = rightdata[j]
                            rightdata[j] = rightdata[j+1]
                            rightdata[j+1] = temp
                        }
                    }
                }

                rightdata.forEach((item,index) => {
                    try{
                        leftdata.forEach((items,indexs) => {
                            if(parseFloat(item.thicknessRight) <= parseFloat(items.thicknessleft)){
                                leftdata.splice(indexs,0,item)
                                // console.log('到这',indexs)
                                throw new Error("break")
                            } else if(items.thicknessRight && parseFloat(item.thicknessRight)<=parseFloat(items.thicknessRight)) {
                                // console.log('到这0')
                                leftdata.splice(indexs,0,item)
                                throw new Error("break")
                            } else if(items.thicknessRight && parseFloat(item.thicknessRight)>parseFloat(items.thicknessRight)) {
                                // console.log('到这1')
                                leftdata.splice(indexs+1,0,item)
                                throw new Error("break")
                            } else if(!items.thicknessRight) {
                                // console.log('到这2')
                                leftdata.splice(indexs,0,item)
                                throw new Error("break")
                            } else {
                                // console.log('到这3')
                                leftdata.splice(indexs+1,0,item)
                                throw new Error("break")
                            }
                        })
                    } catch(e) {
                        console.log(e)
                    }
                })
                finalArray = JSON.parse(JSON.stringify(leftdata))
            } else { array[0].conditionIndex = 1 }
            console.log('排序后',finalArray,array)
            if(finalArray.some(item => item.conditionleft1 && item.thicknessleft1 || item.conditionRight1 && item.thicknessRight1)) {
                finalArray = this.haveRelation(finalArray)
            }
            if(finalArray.length){
                finalArray.forEach((item,index) => {
                    item.conditionIndex = index+1
                })
            }
            return array.length>1?finalArray:array
        },
        haveRelation(arrayh){
            if(arrayh.length>1){
                for(var i = 0;i < arrayh.length-1;i++){
                    for(var j = 0;j < arrayh.length-i-1;j++){
                        if(arrayh[j].thicknessleft == arrayh[j+1].thicknessleft && arrayh[j].conditionRight == arrayh[j+1].conditionRight){
                            if(arrayh[j].thicknessleft1 && parseFloat(arrayh[j].thicknessleft1) > parseFloat(arrayh[j+1].thicknessleft1)){
                                let temp = arrayh[j]
                                arrayh[j] = arrayh[j+1]
                                arrayh[j+1] = temp
                            } else if(arrayh[j].thicknessleft1 && parseFloat(arrayh[j].thicknessleft1) <= parseFloat(arrayh[j+1].thicknessleft1)){
                                let temp = arrayh[j+1]
                                arrayh[j+1] = arrayh[j]
                                arrayh[j] = temp
                            } else if(arrayh[j].thicknessRight1 && parseFloat(arrayh[j].thicknessRight1) > parseFloat(arrayh[j+1].thicknessRight1)){
                                let temp = arrayh[j]
                                arrayh[j] = arrayh[j+1]
                                arrayh[j+1] = temp
                            } else if(arrayh[j].thicknessRight1 && parseFloat(arrayh[j].thicknessRight1) <= parseFloat(arrayh[j+1].thicknessRight1)){
                                let temp = arrayh[j+1]
                                arrayh[j+1] = arrayh[j]
                                arrayh[j] = temp
                            } else{
                                let temp = arrayh[j]
                                arrayh[j] = arrayh[j+1]
                                arrayh[j+1] = temp
                            }
                        }
                    }
                }
                console.log('二层',arrayh)
                if(arrayh.some(item => item.conditionleft2 && item.thicknessleft2 || item.conditionRight2 && item.thicknessRight2)) {
                    arrayh = this.haveRelation2(arrayh)
                }
            }
            // console.log('且',arrayh)
            return arrayh
        },
        haveRelation2(arrayh){
            if(arrayh.length>1){
                for(var i = 0;i < arrayh.length-1;i++){
                    for(var j = 0;j < arrayh.length-i-1;j++){
                        if(arrayh[j].thicknessleft == arrayh[j+1].thicknessleft && arrayh[j].conditionRight == arrayh[j+1].conditionRight){
                            if(arrayh[j].thicknessleft1 == arrayh[j+1].thicknessleft1 && arrayh[j].conditionRight1 == arrayh[j+1].conditionRight1){
                                if(arrayh[j].thicknessleft2 && parseFloat(arrayh[j].thicknessleft2) > parseFloat(arrayh[j+1].thicknessleft2)){
                                    let temp = arrayh[j]
                                    arrayh[j] = arrayh[j+1]
                                    arrayh[j+1] = temp
                                } else if(arrayh[j].thicknessleft2 && parseFloat(arrayh[j].thicknessleft2) <= parseFloat(arrayh[j+1].thicknessleft2)){
                                    let temp = arrayh[j+1]
                                    arrayh[j+1] = arrayh[j]
                                    arrayh[j] = temp
                                } else if(arrayh[j].thicknessRight2 && parseFloat(arrayh[j].thicknessRight2) > parseFloat(arrayh[j+1].thicknessRight2)){
                                    let temp = arrayh[j]
                                    arrayh[j] = arrayh[j+1]
                                    arrayh[j+1] = temp
                                } else if(arrayh[j].thicknessRight2 && parseFloat(arrayh[j].thicknessRight2) <= parseFloat(arrayh[j+1].thicknessRight2)){
                                    let temp = arrayh[j+1]
                                    arrayh[j+1] = arrayh[j]
                                    arrayh[j] = temp
                                } else{
                                    let temp = arrayh[j]
                                    arrayh[j] = arrayh[j+1]
                                    arrayh[j+1] = temp
                                }
                            }
                        }
                    }
                }
                console.log('三层',arrayh)
                if(arrayh.some(item => item.conditionleft3 && item.thicknessleft3 || item.conditionRight3 && item.thicknessRight3)) {
                    arrayh = this.haveRelation3(arrayh)
                }
            }
            // console.log('且',arrayh)
            return arrayh
        },
        haveRelation3(arrayh){
            if(arrayh.length>1){
                for(var i = 0;i < arrayh.length-1;i++){
                    for(var j = 0;j < arrayh.length-i-1;j++){
                        if(arrayh[j].thicknessleft == arrayh[j+1].thicknessleft && arrayh[j].conditionRight == arrayh[j+1].conditionRight){
                            if(arrayh[j].thicknessleft1 == arrayh[j+1].thicknessleft1 && arrayh[j].conditionRight1 == arrayh[j+1].conditionRight1){
                                if(arrayh[j].thicknessleft2 == arrayh[j+1].thicknessleft2 && arrayh[j].conditionRight2 == arrayh[j+1].conditionRight2){
                                    if(arrayh[j].thicknessleft3 && parseFloat(arrayh[j].thicknessleft3) > parseFloat(arrayh[j+1].thicknessleft3)){
                                        let temp = arrayh[j]
                                        arrayh[j] = arrayh[j+1]
                                        arrayh[j+1] = temp
                                    } else if(arrayh[j].thicknessleft3 && parseFloat(arrayh[j].thicknessleft3) <= parseFloat(arrayh[j+1].thicknessleft3)){
                                        let temp = arrayh[j+1]
                                        arrayh[j+1] = arrayh[j]
                                        arrayh[j] = temp
                                    } else if(arrayh[j].thicknessRight3 && parseFloat(arrayh[j].thicknessRight3) > parseFloat(arrayh[j+1].thicknessRight3)){
                                        let temp = arrayh[j]
                                        arrayh[j] = arrayh[j+1]
                                        arrayh[j+1] = temp
                                    } else if(arrayh[j].thicknessRight3 && parseFloat(arrayh[j].thicknessRight3) <= parseFloat(arrayh[j+1].thicknessRight3)){
                                        let temp = arrayh[j+1]
                                        arrayh[j+1] = arrayh[j]
                                        arrayh[j] = temp
                                    } else{
                                        let temp = arrayh[j]
                                        arrayh[j] = arrayh[j+1]
                                        arrayh[j+1] = temp
                                    }
                                }
                            }
                        }
                    }
                    console.log('四层',arrayh)
                }
            }
            // console.log('且',arrayh)
            return arrayh
        },
        priceValid(type,row,index){
            if(row.isvalid) return
            let obj = {
                // H:"1"
            }
            console.log(row.paramName1)
            let paramName = row.paramName?row.paramName[row.paramName.length-1]:''
            let paramName1 = row.paramName1?row.paramName1[row.paramName1.length-1]:''
            let paramName2 = row.paramName2?row.paramName2[row.paramName2.length-1]:''
            let paramName3 = row.paramName3?row.paramName3[row.paramName3.length-1]:''
            if(paramName){ obj[paramName] = '1' }
            if(paramName1 && row.relation && row.conditionleft1 && row.thicknessleft1 || row.conditionRight1 && row.thicknessRight1){ obj[paramName1] = '1' }
            if(paramName2 && row.relation2 && row.conditionleft2 && row.thicknessleft2 || row.conditionRight2 && row.thicknessRight2){ obj[paramName2] = '1' }
            if(paramName3 && row.relation3 && row.conditionleft3 && row.thicknessleft3 || row.conditionRight3 && row.thicknessRight3){ obj[paramName3] = '1' }
            console.log(row)
            if(row.conditionleft && row.thicknessleft || row.conditionRight && row.thicknessRight || row.conditionleft1 && row.thicknessleft1 || row.conditionRight1 && row.thicknessRight1 || row.conditionRight2 && row.thicknessRight2 || row.conditionRight3 && row.thicknessRight3){
                let stringEval = []
                if(row.conditionleft && row.thicknessleft) { stringEval.push(paramName + row.conditionleft + row.thicknessleft)}
                if(row.conditionRight && row.thicknessRight) { stringEval.push(paramName + row.conditionRight + row.thicknessRight)}
                if(row.conditionleft1 && row.thicknessleft1 && row.relation) { stringEval.push(paramName1 + row.conditionleft1 + row.thicknessleft1)}
                if(row.conditionRight1 && row.thicknessRight1 && row.relation) { stringEval.push(paramName1 + row.conditionRight1 + row.thicknessRight1)}
                if(row.conditionleft2 && row.thicknessleft2 && row.relation2) { stringEval.push(paramName2 + row.conditionleft2 + row.thicknessleft2)}
                if(row.conditionRight2 && row.thicknessRight2 && row.relation2) { stringEval.push(paramName2 + row.conditionRight2 + row.thicknessRight2)}
                if(row.conditionleft3 && row.thicknessleft3 && row.relation3) { stringEval.push(paramName3 + row.conditionleft3 + row.thicknessleft3)}
                if(row.conditionRight3 && row.thicknessRight3 && row.relation3) { stringEval.push(paramName3 + row.conditionRight3 + row.thicknessRight3)}
                obj.eval = stringEval.join('&&')
            }
            this.tovalid(obj,index)
        },
        cancelValid(row,index){
            this.priceSchemeList[index].isvalid = false
            this.priceSchemeList[index].isEdicted = true
        },
        getValue(key){
            let value = ''
            this.paramNameLists.forEach((item,index) => {
                if(item.label == key){
                    value = item.value
                }
            })
            return value
        },
        async tovalid(obj1,index){
            let obj = Object.assign({},obj1)
            let data = await verifyEquation(obj)
            if(data.code == '1'){
                this.priceSchemeList[index].isvalid = true
                this.priceSchemeList[index].eval = obj.eval
                this.$message.success(data.msg)
            } else {
                this.$message.error('检查条件是否正确再重试!')
            }
        },
        async getMaterial(){
            let data = await seldplate()
            if(data.code == '500') return
            const errMsg = data.msg
            if(data.code != '1') return this.$message.error(errMsg)
            let children = []
            data.data.forEach((item,index) => {
                let obj = {}
                obj.label = item.texture
                obj.value = item.textureCode
                children.push(obj)
            })
            this.paramNameLists.forEach((item,index) => {
                if(item.label == '材质'){
                    item.children = children
                }
            })
        },
        async getMaterialOnlyForEdict(){
            let data = await seldplate()
            if(data.code == '1'){
                let children = []
                data.data.forEach((item,index) => {
                    let obj = {}
                    obj.label = item.texture
                    obj.value = item.textureCode
                    obj.isCz = true
                    children.push(obj)
                })
                this.paramNameListsForEdict = children.concat(this.paramNameListsForEdict)
                this.handleFilter(this.$route.params.data.processName,this.$route.params.data.processType,this.$route.params.data.schemeType)
                // this.paramNameLists.forEach((item,index) => {
                //     if(item.label == '材质'){
                //         item.children = children
                //     }
                // })
            }
        },
        async handleFilter(processName,processType,schemeType) {
            const data = await findMoneyConfig({processName: processName,schemeType: schemeType,page: this.page,limit: this.limit,isDelete: 0})
            console.log('data',data);
            this.total = data.data.Count
            this.priceSchemeList = []
            this.$set(this.listQuery1, 'processName', processName)
            this.$set(this.listQuery1, 'processType', processType)
            // this.listQuery1.processName = processName
            // this.listQuery1.processType = processType
            data.data.list.forEach((item,index) => {
                if(item.isDelete != 1){
                let obj = {}
                obj.conditionIndex = item.conditionIndex
                obj.standard = item.standard
                obj.standardType = this.getValueStandardTypeName(item.standardType.trim())
                obj.isvalid = true
                obj.eval = item.conditionIf.trim()
                obj.timeId = item.timeId
                obj = Object.assign(obj,this.splitEval(item.conditionIf.trim()))
                this.programmeType = item.schemeType.trim()
                this.priceSchemeList.push(obj)
                item.conditionIf = this.getValue(item.conditionIf)
                item.standardType = this.getValueStandardTypeName(item.standardType)
                }
            })
            this.tableLoading = false
            this.validArray = JSON.parse(JSON.stringify(data.data.list.filter(items => items.isDelete != 1)))
        },
        getValueStandardTypeName(key){
            let value = ''
            this.standardTypeList.forEach((item,index) => {
                if(item.value == key){
                    value = item.name
                }
            })
            return value
        },
        splitEval(value){
            let obj = {paramName: [],paramName1: [],paramName2: [],paramName3: []}
            let singleIf = []
            singleIf = value.trim().split('&&')
            var pattern = new RegExp("[A-Za-z]")
            singleIf.forEach((item,index) => {
                if(!obj.paramName.length){
                    this.paramNameListsForEdict.forEach((item1,index) => {
                        if(item.includes(item1.value)){
                            if(obj.paramName.length) return
                            obj.paramName.push(item1.value)
                            if(item1.isCz) {
                                obj.paramName.unshift('CZ')
                            }
                            obj.paramName.splice(2,obj.paramName.length-2)
                        }
                    })
                    if(this.leftcompareList.some(item2 => item.includes(item2))){
                        this.leftcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionleft = item2
                                    obj.thicknessleft = item.split(item2)[1]
                                } else {
                                    obj.thicknessRight = item.split(item2)[0]
                                    if(item2.trim() == '>='){
                                        obj.conditionRight = '<='
                                    } else {
                                        obj.conditionRight = '<'
                                    }
                                }

                            }
                        })
                    } else {
                        this.rightcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                obj.conditionRight = item2
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionRight = item2
                                    obj.thicknessRight = item.split(item2)[1]
                                } else {
                                    obj.thicknessleft = item.split(item2)[0]
                                    if(item2.trim() == '<='){
                                        obj.conditionleft = '>='
                                    } else {
                                        obj.conditionleft = '>'
                                    }
                                }
                            }
                        })
                    }
                } else if(obj.paramName.length && !obj.paramName1.length && !obj.paramName.some(item2 => item.includes(item2)) || obj.paramName1.length && obj.paramName1.some(item2 => item.includes(item2))){
                    if(!obj.paramName1.length){
                        obj.relation = '且'
                        this.paramNameListsForEdict.forEach((item1,index) => {
                            if(item.includes(item1.value)){
                                obj.paramName1.push(item1.value)
                                if(item1.isCz) {
                                    obj.paramName1.unshift('CZ')
                                }
                                obj.paramName1.splice(2,obj.paramName1.length-2)
                            }
                        })
                    }

                    if(this.leftcompareList.some(item2 => item.includes(item2))){
                        this.leftcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionleft1 = item2
                                    obj.thicknessleft1 = item.split(item2)[1]
                                } else {
                                    obj.thicknessRight1 = item.split(item2)[0]
                                    if(item2.trim() == '>='){
                                        obj.conditionRight1 = '<='
                                    } else {
                                        obj.conditionRight1 = '<'
                                    }
                                }

                            }
                        })
                    } else {
                        this.rightcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                obj.conditionRight1 = item2
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionRight1 = item2
                                    obj.thicknessRight1 = item.split(item2)[1]
                                } else {
                                    obj.thicknessleft1 = item.split(item2)[0]
                                    if(item2.trim() == '<='){
                                        obj.conditionleft1 = '>='
                                    } else {
                                        obj.conditionleft1 = '>'
                                    }
                                }
                            }
                        })
                    }
                } else if(obj.paramName1.length && !obj.paramName2.length && !obj.paramName1.some(item2 => item.includes(item2)) || obj.paramName2.length && obj.paramName2.some(item2 => item.includes(item2))){
                    obj.relation2 = '且'
                    this.paramNameListsForEdict.forEach((item1,index) => {
                        if(item.includes(item1.value)){
                            obj.paramName2.push(item1.value)
                            if(item1.isCz) {
                                obj.paramName2.unshift('CZ')
                            }
                            obj.paramName2.splice(2,obj.paramName2.length-2)
                        }
                    })
                    if(this.leftcompareList.some(item2 => item.includes(item2))){
                        this.leftcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionleft2 = item2
                                    obj.thicknessleft2 = item.split(item2)[1]
                                } else {
                                    obj.thicknessRight2 = item.split(item2)[0]
                                    if(item2.trim() == '>='){
                                        obj.conditionRight2 = '<='
                                    } else {
                                        obj.conditionRight2 = '<'
                                    }
                                }

                            }
                        })
                    } else {
                        this.rightcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                obj.conditionRight2 = item2
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionRight2 = item2
                                    obj.thicknessRight2 = item.split(item2)[1]
                                } else {
                                    obj.thicknessleft2 = item.split(item2)[0]
                                    if(item2.trim() == '<='){
                                        obj.conditionleft2 = '>='
                                    } else {
                                        obj.conditionleft2 = '>'
                                    }
                                }
                            }
                        })
                    }
                } else if(obj.paramName2.length && !obj.paramName2.some(item2 => item.includes(item2))){
                    obj.relation3 = '且'
                    this.paramNameListsForEdict.forEach((item1,index) => {
                        if(item.includes(item1.value)){
                            obj.paramName3.push(item1.value)
                            if(item1.isCz) {
                                obj.paramName3.unshift('CZ')
                            } else {
                                obj.paramName3.splice(0,obj.paramName3.length-1)
                            }
                            console.log('zw',obj,item1)
                        }
                    })
                    if(this.leftcompareList.some(item2 => item.includes(item2))){
                        this.leftcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionleft3 = item2
                                    obj.thicknessleft3 = item.split(item2)[1]
                                } else {
                                    obj.thicknessRight3 = item.split(item2)[0]
                                    if(item2.trim() == '>='){
                                        obj.conditionRight3 = '<='
                                    } else {
                                        obj.conditionRight3 = '<'
                                    }
                                }

                            }
                        })
                    } else {
                        this.rightcompareList.forEach((item2,indexIf) => {
                            if(item.includes(item2)){
                                obj.conditionRight3 = item2
                                if(pattern.test(item.split(item2)[0])){
                                    obj.conditionRight3 = item2
                                    obj.thicknessRight3 = item.split(item2)[1]
                                } else {
                                    obj.thicknessleft3 = item.split(item2)[0]
                                    if(item2.trim() == '<='){
                                        obj.conditionleft3 = '>='
                                    } else {
                                        obj.conditionleft3 = '>'
                                    }
                                }
                            }
                        })
                    }
                }
                // 有paramName.length以及已经存在同参数名
                else if(obj.paramName.length && obj.paramName.some(item2 => item.includes(item2))){
                    obj.paramName.forEach((item3,index) => {
                        if(item.includes(item3) && index == 0){
                            if(this.leftcompareList.some(item2 => item.includes(item2))){
                                this.leftcompareList.forEach((item2,indexIf) => {
                                    if(item.includes(item2)){
                                        if(pattern.test(item.split(item2)[1])){
                                            obj.conditionleft = item2
                                            obj.thicknessleft = item.split(item2)[0]
                                        } else {
                                            obj.thicknessRight = item.split(item2)[1]
                                            if(item2.trim() == '>='){
                                                obj.conditionRight = '<='
                                            } else {
                                                obj.conditionRight = '<'
                                            }
                                        }
                                    }
                                })
                            } else {
                                this.rightcompareList.forEach((item2,indexIf) => {
                                    if(item.includes(item2)){
                                        obj.conditionRight = item2
                                        if(pattern.test(item.split(item2)[0])){
                                            obj.conditionRight = item2
                                            obj.thicknessRight = item.split(item2)[1]
                                        } else {
                                            obj.thicknessleft = item.split(item2)[0]
                                            if(item2.trim() == '<='){
                                                obj.conditionleft = '>='
                                            } else {
                                                obj.conditionleft = '>'
                                            }
                                        }
                                    }
                                })
                            }
                        } else {


                            if(this.leftcompareList.some(item2 => item.includes(item2))){
                                this.leftcompareList.forEach((item2,indexIf) => {
                                    if(item.includes(item2)){
                                        if(pattern.test(item.split(item2)[1])){
                                            obj.conditionleft1 = item2
                                            obj.thicknessleft1 = item.split(item2)[0]
                                        } else {
                                            obj.thicknessRight1 = item.split(item2)[1]
                                            if(item2.trim() == '>='){
                                                obj.conditionRight1 = '<='
                                            } else {
                                                obj.conditionRight1 = '<'
                                            }
                                        }
                                    }
                                })
                            } else {
                                this.rightcompareList.forEach((item2,indexIf) => {
                                    if(item.includes(item2)){
                                        obj.conditionRight1 = item2
                                        if(pattern.test(item.split(item2)[0])){
                                            obj.conditionRight1 = item2
                                            obj.thicknessRight1 = item.split(item2)[1]
                                        } else {
                                            obj.thicknessleft1 = item.split(item2)[0]
                                            if(item2.trim() == '<='){
                                                obj.conditionleft1 = '>='
                                            } else {
                                                obj.conditionleft1 = '>'
                                            }
                                        }
                                    }
                                })
                            }
                        }
                    })

                }
            })
            return obj
        },
        haveManyName(str){
            let value = []
            this.paramNameLists.forEach((item,index) => {
                if(str.includes(item.value)){
                    value.push(item.value)
                }
            })
            let set = new Set(value)
            value = Array.from(set)
            return value
        },
        getValueName(key){
            let value = ''
            this.paramNameLists.forEach((item,index) => {
                if(item.value == key){
                    value = item.label
                }
            })
            return value
        },
        async deleteData(row,index){
            const data = await delMoneyConfig({id: row.timeId})
            if(data.code == '500') return
            if(data.code == '2') return this.$message.error(data.msg)
            if(data.code == '1'){
                  this.priceSchemeList.splice(index,1)
                  this.$message({
                      message:  data.msg,
                      type: 'success'
                   })
            }
        },
        async haveToAddOr(schemeType) {
            let isExit = false
            const data = await findMoneyConfig({schemeType: schemeType,page: this.page,limit: this.limit, isDelete: 0,processName: this.listQuery1.processName})
            if(data.code == '1'){
                if(data.data.list.length){ isExit = true, this.total = data.data.Count }
            }
            return isExit
        },
        // 获取工艺信息
        async getprocessNo(){
            let data = await groupProcessNo()
            if(data.code == '500') return
            let errmsg = data.msg
            if(data.code == '1'){
                this.optionsProcessName = []
                let processNameGzList = [{value: '压铆',label: '压铆'},{value: '攻牙',label: '攻牙'},{value: '钻孔',label: '钻孔'},{value: '沉孔',label: '沉孔'},{value: '涂漆',label: '涂漆'},{value: '滚圆',label: '滚圆'},{value: '拉铆',label: '拉铆'},{value: '拉丝',label: '拉丝'},{value: '撕胶纸',label: '撕胶纸'},{value: '倒角',label: '倒角'},{value: '去毛刺',label: '去毛刺'},{value: '扩孔',label: '扩孔'},{value: '震磨',label: '震磨'}]
                data.data.forEach(item => {
                    let obj = {}
                    obj.label = item.processName
                    obj.value = item.processName
                    if(item.processName.indexOf('钳铆') == 0){
                        obj.children = processNameGzList
                    }
                    this.optionsProcessName.push(obj)
                })
                // this.optionsProcessName = data.data
            } else {
                this.$message({
                    message: errmsg,
                    type: 'error'
                })
            }
        },
        isAliveProcess(e){
            console.log(e)
            this.listQuery1.processName = e[e.length-1]
            if(this.saveToisEdict){
                this.haveToAddOr(this.programmeType).then((res) => {
                    if(res){
                        this.listQuery1.processName = this.$route.params.data.processName
                        this.$message.error('该方案已存在，请前往修改')
                        return
                    }
                })
            }
        }
    },
    // 进入页面获取table信息
    mounted() {
        this.getMaterial()
        this.getprocessNo()
        if(this.$route.params.data){
            if(this.$route.params.data.processName){ this.saveToisEdict = true }
            this.getMaterialOnlyForEdict()
        }

    }
}
</script>

<style>
.spaceBetween{
    justify-content: space-between
}
.flexEnd{
    justify-content: flex-end;
}
.errorBtn{
    display: flex;
    justify-content: flex-end;
}
</style>
